//
//  WelcomeViewController.swift
//  微博001
//
//  Created by apple on 15/12/16.
//  Copyright © 2015年 apple. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage

class WelcomeViewController: UIViewController {
    
    override func loadView() {
        //将根视图 = 背景视图
        view = backImageView
    }

    override func viewDidAppear(animated: Bool) {
        
        //头像和lable的动画效果
        showAnimation()
    }
    
    //头像和lable的动画效果
    private func showAnimation() {
        
        welcomeLabel.alpha = 0
        
        UIView.animateWithDuration(1.5, delay: 0, usingSpringWithDamping: 0.98, initialSpringVelocity: 7, options: [], animations: { () -> Void in
            
            //更改iconName的约束
            let offset = -screenH + 200
            self.iconView.snp_updateConstraints{ (make) -> Void in
                make.bottom.equalTo(view.snp_bottom).offset(offset)
            }

            //立即更新约束
            self.view.layoutIfNeeded()
            
            }) { (_) -> Void in
                
                UIView.animateWithDuration(0.39, animations: { () -> Void in
                    self.welcomeLabel.alpha = 1
                    }, completion: { (_) -> Void in
                        NSNotificationCenter.defaultCenter().postNotificationName(WBSwitchRootVCNotification, object: nil)
                })
        }
        
        
    
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        
        
        setupUI()
        // Do any additional setup after loading the view.
    }

    private func setupUI() {
    
        view.addSubview(iconView)
        view.addSubview(welcomeLabel)
        
        iconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(view.snp_centerX)
            make.bottom.equalTo(view.snp_bottom).offset(-200)
            make.size.equalTo(CGSize(width: 92, height: 92))
        }
        
        welcomeLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(view.snp_centerX)
            make.top.equalTo(iconView.snp_bottom).offset(16)
        }
        
        iconView.sd_setImageWithURL(UserAccountMode().headURL, placeholderImage: UIImage(named: "avatar_default_big"))
        
       // /Users/apple/Desktop/weibo/微博001/微博001/Class/Module/NewFeature/WelcomeViewController.swift:100:62: Use of unresolved identifier 'UserAccountViewModel'
        //设置iconView的圆角
        iconView.layer.cornerRadius = 46
        iconView.layer.masksToBounds = true

    }
    
    // MARK: 懒加载所有的子视图
    private lazy var backImageView: UIImageView = UIImageView(image: UIImage(named: "ad_background"))
    private lazy var iconView: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    private lazy var welcomeLabel: UILabel = UILabel(title: (UserAccountMode().userName ?? "") + " 欢迎归来", color: UIColor.lightGrayColor(), fontSize: 16)
    



}
